﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ServeurRSS_1_0.Source.Model;
using System.ServiceModel.Activation;

namespace ServeurRSS_1_0
{
     [AspNetCompatibilityRequirements(
                 RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class SessionManagerService
    {
 

         public SessionManagerService()
         {
            System.Web.ApplicationServices.AuthenticationService.Authenticating += new EventHandler<System.Web.ApplicationServices.AuthenticatingEventArgs>(AuthenticationService_Authenticating);
        }

        public delegate DataUser AuthentificationDelegate(DataUser user);
        public AuthentificationDelegate TryingAuthenticateUser
        {
            get;
            set;
        }



        void AuthenticationService_Authenticating(object sender, System.Web.ApplicationServices.AuthenticatingEventArgs e)
        {
            //if (TryingAuthenticateUser != null)
            //{
                DataUser user = new DataUser();
                user.email = e.UserName;
                user.password = e.Password;
                try
                {
                    if (TryingAuthenticateUser != null)
                        TryingAuthenticateUser(user);
                    e.Authenticated = true;
                    e.AuthenticationIsComplete = true;
                }
                catch (Exception ex)
                {
                   e.Authenticated = false;
                    e.AuthenticationIsComplete = false;
                }
            //}
 
        }
    }
}